/*
 * Created on 2005-3-11
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package nc.tb.pub.table;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;

import nc.tb.app.CommonPlan;
import nc.vo.pub.lang.UFBoolean;

/**
 * @author liwei
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ExeTableRender extends DefaultTableCellRenderer {

	/**
	 * 
	 */
	public ExeTableRender() {
		super();
		// TODO Auto-generated constructor stub
	}
	/**
    *
    * Returns the default table cell renderer.
    *
    * @param table  the <code>JTable</code>
    * @param value  the value to assign to the cell at
    *			<code>[row, column]</code>
    * @param isSelected true if cell is selected
    * @param hasFocus true if cell has focus
    * @param row  the row of the cell to render
    * @param column the column of the cell to render
    * @return the default table cell renderer
    */
   public Component getTableCellRendererComponent(JTable table, Object value,
                         boolean isSelected, boolean hasFocus, int row, int column) {

	TableModel model=table.getModel();
	
	if(model instanceof SortedTableModel){
		row = ((SortedTableModel)model).getSortedRow(row);
	}
	
	if (model instanceof AbstractPlanTableModel &&column==2){
		CommonPlan[] plans=((AbstractPlanTableModel )model).getPlan();
		UFBoolean autoexec=plans[row].getPlanInfo().getAutoexecflag();
		if (autoexec!=null&&autoexec.booleanValue()){
			this.setHorizontalTextPosition(SwingConstants.LEFT);
			this.setIcon(new ImageIcon(getClass().getResource("/images/ntbimage/clock.gif")));
		}
		else
			this.setIcon(null);
	}
   	super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
   	return this;
   }
   

}
